import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/news_list")
public class News_list extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List list = new ArrayList();
        list.add(new News("标题一","2022.4.27"));
        list.add(new News("标题二","2022.4.28"));
        String json = JSON.toJSONString(list);
        //response就是在编写的程序发给网页
        //request就是从网页取信息到程序
        //下面这句话一般都要写，只要写中文就要写，将网页设置成UTF-8
        response.setContentType("text/html;Charset=UTF-8");
        response.getWriter().println(json);
    }
}
